import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import javax.servlet.ServletResponse;

/**
 *
 * @author andre
 */
public class FilterCheckedLogin implements Filter {

    public void init(FilterConfig filterConfig) throws ServletException {
        
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
            HttpSession session = ((HttpServletRequest)request).getSession();
            String isLogging = (String)session.getAttribute("isLogging");

            if(isLogging==null){
                  session.setAttribute("msg", "Informe o login e a senha novamente!");
                  ((HttpServletResponse)response).sendRedirect("index.jsp");
            }else{
                  chain.doFilter(request, response);
            }        
    }

    public void destroy() {
        
    }

}